import JSZip, { file } from "jszip";
import { FileLoader } from "three";
import { ZipBlobPathMap } from "../dto/ZipBlobPathMap";

// 私有工具
const fileLoader: FileLoader = new FileLoader();

export class LoaderHelper {

  private constructor() {}

  public static async loadZipFromUrlToBlob(url: string) {
    const zip = new JSZip();

    const zipBlobPathMap: ZipBlobPathMap = new Map();

    const fileArrayBuffer: ArrayBuffer = await LoaderHelper.loadUrlToArrayBuffer(url);

    await zip.loadAsync(fileArrayBuffer);

    console.log(zip.files);

    Object.keys(zip.files).forEach(async (fileName) => {
      const file = zip.files[fileName];
      const blob = await file.async('blob');
    })
  }

  /** 加载url文件为arrayBuffer
   * @param url
   * @returns
   */
  public static loadUrlToArrayBuffer(url: string): Promise<ArrayBuffer> {
    return (fileLoader.setResponseType('arraybuffer').loadAsync(url)) as Promise<ArrayBuffer>;
  }


}
